import com.na.onlineservey.AnsweringType
import com.na.onlineservey.Project

class BootStrap {

    def init = { servletContext ->
        createQuestionType();
        createProject();
    }
    def destroy = {
    }

    private void createQuestionType() {
        if (AnsweringType.count() < 1) {
            AnsweringType answeringType1 = new AnsweringType(code: '001', name: 'Single Select')
            AnsweringType answeringType2 = new AnsweringType(code: '002', name: 'Multiple Select')
            AnsweringType answeringType3 = new AnsweringType(code: '003', name: 'Input')
            answeringType1.save(true)
            answeringType2.save(true)
            answeringType3.save(true)
        }
    }

    private void createProject() {
        if (Project.count() < 1) {
            Project project1 = new Project(code: '001', name: 'Project1', isClosedProject: false, isRunningProject: true)
            Project project2 = new Project(code: '002', name: 'Project2', isClosedProject: false, isRunningProject: true)
            project1.save(true)
            project2.save(true)
        }
    }
}
